Skip to content

fix: finalize code-owner fallback worktree before cleanup - #164

Open
cwbcheng wants to merge 1 commit into
jeremymcs:mainfrom
cwbcheng:pr/fallback-finalize
Open

fix: finalize code-owner fallback worktree before cleanup#164
cwbcheng wants to merge 1 commit into
jeremymcs:mainfrom
cwbcheng:pr/fallback-finalize

Conversation

@cwbcheng

@cwbcheng cwbcheng commented Aug 5, 2026

Copy link
Copy Markdown

Problem

The code-owner fallback agent is asked (in its prompt) to commit and push its own changes. But agents — especially slower model-backed ones — frequently finish without doing so: they edit files, then return a successful exit without committing or pushing.

Previously, PatchDeck marked the fallback run completed and removed the worktree in a finally block, discarding the agent's edits. The PR branch stayed at the old head and review threads were never resolved, even though the agent had done real work. We observed a run that modified 21 files (a correct fix for a review comment) and then lost all of it.

Changes

server/babysitter.ts — after a successful code-owner fallback agent run, before the worktree is cleaned up, PatchDeck now finalizes the PR branch:

  1. Commits any uncommitted agent edits (git add -A + git commit).
  2. Pushes the local head to the PR head branch (git push <remote> HEAD:<headRef>).
  3. Fetches the remote head and verifies it matches the local head; throws if the work was not reflected on the branch.

If the agent already committed and pushed, git status --porcelain is empty and the push is a no-op success — the verification still confirms the head matches.

Tests

  • New: runQueuedBabysitPR commits and pushes uncommitted code-owner fallback agent changes — a fallback agent that leaves uncommitted edits results in git add -A, git commit, and git push HEAD:<branch> to the PR branch.

Environment

  • Node.js 22, WSL2, codex CLI 0.146.0 (DeepSeek-backed provider)

The code-owner fallback agent is asked to commit and push its own
changes, but agents sometimes finish without doing so (e.g. a truncated
model response). Previously PatchDeck marked the fallback run completed
and removed the worktree, discarding the agent's edits and leaving the
PR branch and review threads untouched.

After a successful fallback agent run, PatchDeck now:
- commits any uncommitted agent edits in the worktree,
- pushes the local head to the PR head branch,
- verifies the remote head matches the local head.

Adds a regression test that a fallback agent leaving uncommitted edits
results in git add/commit/push to the PR branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant